package com.bdqn.t382.reflection;

import java.lang.reflect.Field;

public class AccessPersonFields {
    public static void main(String[] args) {
        try {
            Class cls = Class.forName("com.bdqn.t382.reflection.Person");
            Object person = cls.newInstance();
            Field name = cls.getDeclaredField("name");
            name.setAccessible(true);
            System.out.println("赋值前的 name：" + name.get(person));
            name.set(person, "New Person");
            System.out.println("赋值后的 name：" + name.get(person));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
